package com.jsong.linuo.string;

/**
 * @Author: 黎诺
 * @CreateTime: 2025-05-01
 * @Description: StringBuilder练习:定义一个数组以[元素1,元素2,...]的形式输出,用StringBuilder拼接
 */

public class StringBuilder03 {
    public static void main(String[] args) {
        //1.定义数组
        String[] a = {"呵呵","哈哈","好好"};
        //2.循环
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < a.length; i++) {
            if (i==0){
                sb.append("[").append(a[i]).append(",");
            }else if(i==a.length-1){
                sb.append(a[i]).append("]");
            }else {
                sb.append(a[i]).append(",");
            }
        }

        //输出
        System.out.println(sb);


    }
}
